home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume28 / ssh-1.3 / part01 next >
Encoding:
Text File  |  1992-03-22  |  15.3 KB  |  490 lines

  1. Newsgroups: comp.sources.misc
  2. From: etxerus@james.ericsson.se (Hans Beckerus LG/THB)
  3. Subject:  v28i117:  ssh-1.3 - Split & Strip appended shell archives, Part01/01
  4. Message-ID: <1992Mar22.025951.4437@sparky.imd.sterling.com>
  5. X-Md4-Signature: ada86a6b743d5d10725e58083725f5b8
  6. Date: Sun, 22 Mar 1992 02:59:51 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: etxerus@james.ericsson.se (Hans Beckerus LG/THB)
  10. Posting-number: Volume 28, Issue 117
  11. Archive-name: ssh-1.3/part01
  12. Environment: UNIX
  13. Supersedes: ssh-1.2: Volume 28, Issue 98
  14.  
  15. SSH version 1.30 
  16.  
  17. This version of ssh is based on the comments I received
  18. from all of you out there in the world since the first
  19. release. 
  20.  
  21. There is no new functions implemented but the sourcecode
  22. is updated and improved for better performance. Also the
  23. makefile has been changed since the problems with the 
  24. 'strcasecmp' function did not only affect System V sites.
  25.  
  26. I hope this version will work better then the last but as
  27. you all probably know there is a lot of sites out there
  28. so I cannot promise anything!
  29.  
  30. As for now this is the final version and faults reported
  31. after this release will of course be answered but I am not
  32. intending to post any new versions.
  33.  
  34. Cheers!
  35.  
  36.  /HaB
  37. --------
  38. #! /bin/sh
  39. # This is a shell archive.  Remove anything before this line, then unpack
  40. # it by saving it into a file and typing "sh file".  To overwrite existing
  41. # files, type "sh file -c".  You can also feed this as standard input via
  42. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  43. # will see the following message at the end:
  44. #        "End of shell archive."
  45. # Contents:  README Makefile ssh.c strcasecmp.c
  46. # Wrapped by etxerus@james16 on Thu Mar 19 16:28:56 1992
  47. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  48. if test -f 'README' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'README'\"
  50. else
  51. echo shar: Extracting \"'README'\" \(975 characters\)
  52. sed "s/^X//" >'README' <<'END_OF_FILE'
  53. X
  54. XSSH version 1.30 
  55. X
  56. XThis version of ssh is based on the comments I received
  57. Xfrom all of you out there in the world since the first
  58. Xrelease. 
  59. X
  60. XThere is no new functions implemented but the sourcecode
  61. Xis updated and improved for better performance. Also the
  62. Xmakefile has been changed since the problems with the 
  63. X'strcasecmp' function did not only affect System V sites.
  64. X
  65. XI hope this version will work better then the last but as
  66. Xyou all probably know there is a lot of sites out there
  67. Xso I cannot promise anything!
  68. X
  69. XAs for now this is the final version and faults reported
  70. Xafter this release will of course be answered but I am not
  71. Xintending to post any new versions on the uunet.
  72. X
  73. X
  74. XCheers!
  75. X
  76. X________________________________________________________________________________
  77. XHans Beckerus                  Phone  : +46 8 719 59 60     
  78. XEricsson Telecom AB            Memo   : ETX.ETXERUS
  79. XAXE System Design              E-mail : etxerus@james.ericsson.se
  80. X126 25 Stockholm
  81. XSWEDEN
  82. END_OF_FILE
  83. if test 975 -ne `wc -c <'README'`; then
  84.     echo shar: \"'README'\" unpacked with wrong size!
  85. fi
  86. # end of 'README'
  87. fi
  88. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  89.   echo shar: Will not clobber existing file \"'Makefile'\"
  90. else
  91. echo shar: Extracting \"'Makefile'\" \(803 characters\)
  92. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  93. X#
  94. X# Makefile for ssh 1.30
  95. X#
  96. X
  97. X# Destination directory for binary
  98. XBINDIR= /usr/local/bin
  99. X
  100. XCC= cc
  101. XFLAGS= -O
  102. XPROG= ssh
  103. X
  104. X# For sites which do not have the function 'strcasecmp'.
  105. X#SOURCES= ssh.c strcasecmp.c
  106. X#OBJ= ssh.o strcasecmp.o
  107. X
  108. X# For sites that have the function 'strcasecmp'.
  109. XSOURCES= ssh.c
  110. XOBJS= ssh.o
  111. X
  112. X# Do not change the SHELL definition except if
  113. X# (by some reason) 'sh' is located somewhere
  114. X# else then in /bin.
  115. XDSHELL= -DSHELL=\"/bin/sh\"
  116. X
  117. X# SUN/SPARC:
  118. X# This should work for all SUN:s.
  119. XTARGET= -DSUN
  120. X# SYSV:
  121. X# This should work for all SysV sites.
  122. X#TARGET= -DSYSV
  123. X
  124. XSCCSID= -DSCCSID
  125. XDEFINES= $(TARGET) $(SCCSID) $(DSHELL)
  126. XCFLAGS= $(FLAGS) $(DEFINES)
  127. X
  128. X$(PROG): $(OBJS)
  129. X    $(CC) $(CFLAGS) -o $(PROG) $(OBJS)
  130. X
  131. Xclean:
  132. X    rm -f core $(PROG) $(OBJS)
  133. X
  134. Xinstall: $(PROG)
  135. X    strip $(PROG)
  136. X    mv $(PROG) $(BINDIR)
  137. END_OF_FILE
  138. if test 803 -ne `wc -c <'Makefile'`; then
  139.     echo shar: \"'Makefile'\" unpacked with wrong size!
  140. fi
  141. # end of 'Makefile'
  142. fi
  143. if test -f 'ssh.c' -a "${1}" != "-c" ; then 
  144.   echo shar: Will not clobber existing file \"'ssh.c'\"
  145. else
  146. echo shar: Extracting \"'ssh.c'\" \(6442 characters\)
  147. sed "s/^X//" >'ssh.c' <<'END_OF_FILE'
  148. X/* @(#)ssh.c 1.30 (HaB) 92/03/17
  149. X *
  150. X * NAME:
  151. X *    ssh
  152. X *
  153. X * SYNTAX:
  154. X *    ssh [-h]
  155. X *        [-x] < shar_archive
  156. X *        [-v] 
  157. X *
  158. X * OPTIONS:
  159. X *    -h    Display usage information.
  160. X *
  161. X *    -x    Extract files in archive instead
  162. X *          of splitting it into parts. 
  163. X *
  164. X *    -v    Display version information. 
  165. X *
  166. X *    Without any options ssh splits archives
  167. X *    into extractable 'PartXX' files.
  168. X *
  169. X * DESCRIPTION:
  170. X *    Splits, strips and extracts appended shell
  171. X *    archives and stores the result in 'PartXX'
  172. X *    files (not when extracting). 
  173. X *
  174. X * NOTES:
  175. X *    The program should work on all archives created
  176. X *    using 'shar' (or equals) provided that they have
  177. X *    not been changed since they were first generated.  
  178. X *
  179. X * BUGS:
  180. X *    I have noticed that when the archives contains
  181. X *    archives themselves (happens sometimes) it does 
  182. X *    not always work properly.
  183. X *
  184. X * DATE:
  185. X *    1992-03-17
  186. X *
  187. X * AUTHOR:
  188. X *    Hans C. Beckerus         
  189. X *    etxerus@james.ericsson.se
  190. X *
  191. X *    Thanks to Pat Myrto, rwing!pat@relay.EU.net, for
  192. X *    solving the problems with System V compatibility.
  193. X *    
  194. X * DISCLAIMER:
  195. X *    This program is free to distribute to anyone as 
  196. X *    long as the code is not changed in anyway without
  197. X *    me knowing about it.  
  198. X *
  199. X *                                            /HaB :-)
  200. X */
  201. X
  202. X#include <stdio.h>
  203. X#include <string.h>
  204. X#include <malloc.h>
  205. X
  206. X#define SEARCH  0
  207. X#define START   1
  208. X#define INSIDE  2
  209. X#define MSTEP   80     /* Allocation steps */
  210. X
  211. X#ifndef SHELL
  212. X#define SHELL  "/bin/sh"     /* Just in case... */
  213. X#endif
  214. X
  215. X#ifdef SYSV     /* HPUX/SYSV */
  216. X#include <sys/types.h>     /* Non-ansi/PONIX sites needs this for size_t */
  217. X#define nl_fprintf  fprintf     /* Provided for XPG2 compatibility */
  218. X#define nl_sprintf  sprintf
  219. X#define nl_strcmp   strcmp
  220. Xsize_t msize;
  221. X#endif
  222. X
  223. X#ifdef SUN     /* SunOS/Berkeley */
  224. Xunsigned int msize;
  225. X#endif
  226. X
  227. X#ifdef SCCSID
  228. Xchar sccsid[] = "@(#)ssh.c    1.30 (HaB) 92/03/17";
  229. X#endif
  230. X
  231. Xenum boolean {     /* Boolean constants */
  232. X    FALSE,
  233. X    TRUE
  234. X};
  235. X
  236. Xchar *pattern[] = {                 /* Add more patterns here if needed.   */ 
  237. X    "# this is a shell archive",
  238. X    "# this is part", 
  239. X    "#!/bin/sh",
  240. X    "# !/bin/sh",
  241. X    "#! /bin/sh",
  242. X    ""     /* This is a flag and must not be removed */
  243. X};
  244. X
  245. X/* usage:
  246. X * 
  247. X * Display usage information and exit with status rc.
  248. X *
  249. X */
  250. X
  251. Xvoid usage (rc) 
  252. X
  253. Xint rc;     /* Return code */
  254. X
  255. X{
  256. X    puts ("\nUsage: ssh [-h]");
  257. X    puts ("           [-x] < shar_archive");
  258. X    puts ("           [-v]\n");
  259. X    puts ("Options:");
  260. X    puts ("  -h       - This help text.");
  261. X    puts ("  -x       - Extract files in archive instead");
  262. X    puts ("             of splitting it into parts.");
  263. X    puts ("  -v       - Display version information.\n");
  264. X    puts ("  Without any options ssh splits archives");
  265. X    puts ("  into extractable 'PartXX' files.\n");
  266. X    exit (rc);
  267. X}
  268. X
  269. Xvoid main (argn, argv)
  270. X
  271. Xint   argn;
  272. Xchar *argv[];
  273. X
  274. X{
  275. X    FILE     *fr = stdin;          /* Input filepointer  */
  276. X    FILE     *fw;                  /* Output filepointer */
  277. X    FILE     *pipe;                /* Stream pipe        */
  278. X    int       state = SEARCH;      /* The current state  */
  279. X    int       fc = 0;              /* File part counter  */
  280. X    int       extract = FALSE;     /* Extract/write flag */
  281. X    char     *s;                   /* Read line          */
  282. X    char      fout[7];             /* Output filenames   */
  283. X    register  j = 0;               /* Counter            */
  284. X    register  c;                   /* Read character     */
  285. X
  286. X    /* Check the arguments if any */
  287. X    while (--argn) {
  288. X        argv++;
  289. X        if (!(strcmp (*argv, "-h"))) {     /* Help screen */
  290. X            if (!(argn-1))     /* Single option */
  291. X                usage (0);
  292. X        }
  293. X        else if (!(strcmp (*argv, "-x"))) {     /* Extract files */ 
  294. X            if (!(argn-1)) {     /* Single option */
  295. X                extract = TRUE;
  296. X                continue;
  297. X            }
  298. X        }
  299. X        else if (!(strcmp (*argv, "-v"))) {
  300. X            if (!(argn-1)) {     /* Single option */
  301. X                puts ("ssh v1.30  (bugs to etxerus@james.ericsson.se)");
  302. X                exit (0);
  303. X            }
  304. X        }
  305. X        usage (1);
  306. X    }  
  307. X
  308. X    msize = MSTEP;
  309. X    s = malloc (msize);     /* Allocate buffer */
  310. X
  311. X    while ((c = getc (fr)) != EOF) {
  312. X    if (c != '\n') {     /* Check for EOL */
  313. X        s[j++] = c;
  314. X            if (j == msize) {
  315. X                msize += MSTEP;
  316. X                if ((s = realloc (s, msize)) == NULL) {
  317. X                    fprintf (stderr, "ssh: Allocation error, cannot continue.\n");
  318. X                    exit (1);
  319. X                }
  320. X            }
  321. X        }
  322. X    else {
  323. X        s[j] = '\0';     /* One line has been read */
  324. X        switch (state) {
  325. X        case SEARCH:
  326. X                    for (j = 0; pattern[j][0] != NULL; j++) {
  327. X                        if (!(strncasecmp (s, pattern[j], strlen (pattern[j])))) {
  328. X                            state = START;
  329. X                            break;    
  330. X                        }
  331. X                    }
  332. X                    if (state != START)
  333. X                        break;
  334. X
  335. X        case START:     /* Start writing or extracting */
  336. X                    if (!extract) {
  337. X                sprintf (fout, "Part%.2d", ++fc);
  338. X                fw = fopen (fout, "w");
  339. X                        fprintf (fw, "%s\n", s);
  340. X                    }
  341. X                    else {
  342. X                        if ((pipe = popen (SHELL, "w")) == NULL) {
  343. X                            fprintf (stderr, "ssh: Cannot create process.\n");
  344. X                            exit (1);
  345. X                        }
  346. X                        fprintf (pipe, "%s\n", s);
  347. X                    }
  348. X                    state = INSIDE;
  349. X            break;
  350. X
  351. X                case INSIDE:
  352. X            if (!(strcmp (s, "exit 0"))) {     /* Look for end */
  353. X                        if (!extract) {
  354. X                            fprintf (fw, "%s\n", s);
  355. X                            fclose (fw);
  356. X                        }
  357. X                        else {
  358. X                            fprintf (pipe, "%s\n", s);
  359. X                            pclose (pipe);
  360. X                        }
  361. X                        state = SEARCH;
  362. X                    }
  363. X                    else {
  364. X                        if (extract)
  365. X                            fprintf (pipe, "%s\n", s);
  366. X                        else
  367. X                fprintf (fw, "%s\n", s);
  368. X                    }
  369. X            break;
  370. X            }
  371. X            j = 0;    /* Reset counter */
  372. X        }
  373. X    }
  374. X}
  375. END_OF_FILE
  376. if test 6442 -ne `wc -c <'ssh.c'`; then
  377.     echo shar: \"'ssh.c'\" unpacked with wrong size!
  378. fi
  379. # end of 'ssh.c'
  380. fi
  381. if test -f 'strcasecmp.c' -a "${1}" != "-c" ; then 
  382.   echo shar: Will not clobber existing file \"'strcasecmp.c'\"
  383. else
  384. echo shar: Extracting \"'strcasecmp.c'\" \(3807 characters\)
  385. sed "s/^X//" >'strcasecmp.c' <<'END_OF_FILE'
  386. X/*
  387. X * Copyright (c) 1987 Regents of the University of California.
  388. X * All rights reserved.
  389. X *
  390. X * Redistribution and use in source and binary forms are permitted
  391. X * provided that the above copyright notice and this paragraph are
  392. X * duplicated in all such forms and that any documentation,
  393. X * advertising materials, and other materials related to such
  394. X * distribution and use acknowledge that the software was developed
  395. X * by the University of California, Berkeley.  The name of the
  396. X * University may not be used to endorse or promote products derived
  397. X * from this software without specific prior written permission.
  398. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  399. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  400. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  401. X */
  402. X
  403. X#ifdef    SCCSID
  404. X#define    LIBC_SCCS
  405. X#endif
  406. X
  407. X#if defined(LIBC_SCCS) && !defined(lint)
  408. Xstatic char sccsid[] = "@(#)strcasecmp.c    5.6 (Berkeley) 6/27/88";
  409. X#endif /* LIBC_SCCS and not lint */
  410. X
  411. X#include <sys/types.h>
  412. X
  413. X/*
  414. X * This array is designed for mapping upper and lower case letter
  415. X * together for a case independent comparison.  The mappings are
  416. X * based upon ascii character sequences.
  417. X */
  418. Xstatic u_char charmap[] = {
  419. X    '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  420. X    '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  421. X    '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  422. X    '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  423. X    '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  424. X    '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  425. X    '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  426. X    '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  427. X    '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  428. X    '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  429. X    '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  430. X    '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  431. X    '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  432. X    '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  433. X    '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  434. X    '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  435. X    '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  436. X    '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  437. X    '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  438. X    '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  439. X    '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  440. X    '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  441. X    '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  442. X    '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  443. X    '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  444. X    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  445. X    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  446. X    '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
  447. X    '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  448. X    '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  449. X    '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  450. X    '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  451. X};
  452. X
  453. Xstrcasecmp(s1, s2)
  454. X    char *s1, *s2;
  455. X{
  456. X    register u_char    *cm = charmap,
  457. X            *us1 = (u_char *)s1,
  458. X            *us2 = (u_char *)s2;
  459. X
  460. X    while (cm[*us1] == cm[*us2++])
  461. X        if (*us1++ == '\0')
  462. X            return(0);
  463. X    return(cm[*us1] - cm[*--us2]);
  464. X}
  465. X
  466. Xstrncasecmp(s1, s2, n)
  467. X    char *s1, *s2;
  468. X    register int n;
  469. X{
  470. X    register u_char    *cm = charmap,
  471. X            *us1 = (u_char *)s1,
  472. X            *us2 = (u_char *)s2;
  473. X
  474. X    while (--n >= 0 && cm[*us1] == cm[*us2++])
  475. X        if (*us1++ == '\0')
  476. X            return(0);
  477. X    return(n < 0 ? 0 : cm[*us1] - cm[*--us2]);
  478. X}
  479. END_OF_FILE
  480. if test 3807 -ne `wc -c <'strcasecmp.c'`; then
  481.     echo shar: \"'strcasecmp.c'\" unpacked with wrong size!
  482. fi
  483. # end of 'strcasecmp.c'
  484. fi
  485. echo shar: End of shell archive.
  486. exit 0
  487.  
  488. exit 0 # Just in case...
  489.